Ulozeni a nacteni BLOB do FB 1.5

Otázka od: info@gastrocentrum.cz

10. 9. 2004 11:16

Ahoj

Jiz nekolik hodin resim jak ulozit Record packed do Blobu pres IBX .
Zkousel jsem to pomoci MemoryStreamu atd. ale nedari se.

Vi nekdo jak na to

Diky Heinisch Jiri



Odpovedá: Milan Tomes

16. 9. 2004 11:29

Co treba takto:

var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;
  try
    MS.Size := SizeOf(packed_record);
    CopyMemory(MS.Memory, @packed_record, MS.Size);
// a ted uloz MS do blobu
  finally
    freeAndNil(MS);
  end;
end;

S pozdravem

Milan Tomes

P.S.: Nezkousel jsem to, ale melo by to nejak fungovat...

> [mailto:delphi-l-owner@clexpert.cz]On Behalf Of info@gastrocentrum.cz
> Sent: Friday, September 10, 2004 11:50 AM
>
> Jiz nekolik hodin resim jak ulozit Record packed do Blobu pres IBX .
> Zkousel jsem to pomoci MemoryStreamu atd. ale nedari se.


Odpovedá: info@gastrocentrum.cz

16. 9. 2004 13:06

Ahoj

Tak nejak to delam, problem je ale jak Ten stream ulozit do blobu
pres IBX (v7,04) v D7 a pak to zase do streamu nacist


 Diky za pomoc
J. Heinisch

> Co treba takto:
>
> var
> MS: TMemoryStream;
> begin
> MS := TMemoryStream.Create;
> try
> MS.Size := SizeOf(packed_record);
> CopyMemory(MS.Memory, @packed_record, MS.Size);
> // a ted uloz MS do blobu
> finally
> freeAndNil(MS);
> end;
> end;
>
> S pozdravem
>
> Milan Tomes
>
> P.S.: Nezkousel jsem to, ale melo by to nejak fungovat...
>
> > [mailto:delphi-l-owner@clexpert.cz]On Behalf Of info@gastrocentrum.cz
> > Sent: Friday, September 10, 2004 11:50 AM
> >
> > Jiz nekolik hodin resim jak ulozit Record packed do Blobu pres IBX .
> > Zkousel jsem to pomoci MemoryStreamu atd. ale nedari se.
>
>
>
>


Odpovedá: Robert Suska

16. 9. 2004 13:42

Ahoj!

Uvediem priklad ako pracovat z RichEdit rtf textom pri ukladani/citani do/z
blobu pomocou streamu. Upravit to tak aby to bolo pre record je uz na Tebe.

uloz do databazy

var
  Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  Stream.Clear;
  RichEdit1.Lines.SaveToStream(Stream);
  Stream.Position := 0;
// update alebo insert
  SQLSave.Params[X].LoadFromStream(Stream);
  ...

nacitaj z databazy

var
  Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  Stream.Clear;
// sql select
  TBlobField(QLoadSQL.FieldByName('rtf')).SaveToStream(Stream);
  Stream.Position := 0;
  RichEdit1.Lines.Clear;
  RichEdit1.Lines.LoadFromStream(Stream);
...

Robo

> Tak nejak to delam, problem je ale jak Ten stream ulozit do blobu
> pres IBX (v7,04) v D7 a pak to zase do streamu nacist


Odpovedá: Milan Tomes

16. 9. 2004 15:13

Nacteni z DB

var
  BlobStream: TStream;

            if IBDataSet.Fields[i].IsBlob then
            begin
              BlobStream := IBDataSet.CreateBlobStream(IBDataSet.Fields[i],
bmReadWrite);
              try
                ColumnByName(IBDataSet.Fields[i].FieldName).asBlob.Size :=
0;
                ColumnByName(IBDataSet.Fields[i].FieldName).asBlob.CopyFrom(
BlobStream, 0);
                ColumnByName(IBDataSet.Fields[i].FieldName).asBlob.Position
:= 0;
              finally
                BlobStream.Free;
              end;
            end

Ulozeni

IBSQL.SQL.Text := 'insert into blobs (blob1) values (:blob1)';
IBSQL.Prepare;
IBSQL.ParamByName('blob1').LoadFromStream(Zdrojovy_stream);
IBSQL.Execute;

S pozdravem

Milan Tomes




> [mailto:delphi-l-owner@clexpert.cz]On Behalf Of info@gastrocentrum.cz
> Sent: Thursday, September 16, 2004 1:32 PM
>
> Ahoj
>
> Tak nejak to delam, problem je ale jak Ten stream ulozit do blobu
> pres IBX (v7,04) v D7 a pak to zase do streamu nacist


Odpovedá: info@gastrocentrum.cz

22. 9. 2004 6:19

Ahoj

To: Milan Tomes
Delphi mi nezna "ColumnByName"

> ColumnByName(IBDataSet.Fields[i].FieldName).asBlob.Size := 0;


J. H..



Odpovedá: Milan Tomes

22. 9. 2004 7:53

ColumnByName je metoda meho objektu z frameworku. V promenne BlobStream mas
nacteny stream s BLOBem - muzes si s nim delat co chces (ulozit na disk
apod...)

S pozdravem

Milan Tomes


> [mailto:delphi-l-owner@clexpert.cz]On Behalf Of info@gastrocentrum.cz
> Sent: Wednesday, September 22, 2004 7:20 AM
>
> Ahoj
>
> To: Milan Tomes
> Delphi mi nezna "ColumnByName"
>
> > ColumnByName(IBDataSet.Fields[i].FieldName).asBlob.Size := 0;